package vis.core.common.valid.handler;


import vis.core.common.util.StringKit;
import vis.core.common.valid.NotBlank;
import vis.core.common.valid.base.ValidBaseHandler;
import vis.core.domain.sys.ServiceException;
import org.springframework.stereotype.Component;

/**
 * 枚举校验规则实现
 */
@Component
public class NotBlankHandler implements ValidBaseHandler<NotBlank, Object> {

    // 第一个参数应该是注解
    @Override
    public void valid(NotBlank annotation, String paramName, Object paramValue) {
        if (paramValue == null)
            throw new ServiceException(StringKit.blankDefStr(annotation.msg(), "参数：" + paramName + "，不能为空"));

        if (paramValue instanceof String) {
            if (StringKit.isBlank(paramValue.toString()))
                throw new ServiceException(StringKit.blankDefStr(annotation.msg(), "参数：" + paramName + "，不能为空"));
        }

    }

}
